package com.efrei.schoolmanager.model.obj;

import java.io.Serializable;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import com.efrei.schoolmanager.exceptions.LogicException;
import com.efrei.schoolmanager.tools.Tools;

public class Classe implements Serializable {
	private static final long serialVersionUID = 7428926011053478087L;

	/* Attributs */
	private int classeId;
	private String nom;
	private int promotion;
	private Niveau niveau;

	private Set<Eleve> eleves = new HashSet<Eleve>();
	private Map<Matiere, Enseignant> enseignantsResponsables = new HashMap<Matiere, Enseignant>();
	private Set<Note> notes = new HashSet<Note>();

	public Classe() {
	}

	public Classe(String nom, int promotion, Niveau niveau)
			throws LogicException {
		super();
		if (nom == null || nom.equals(""))
			throw new LogicException("nom vide");
		this.nom = nom;
		if (promotion < 1)
			throw new LogicException("promotion < 0");
		this.promotion = promotion;
		if (niveau == null)
			throw new LogicException("Niveau null");
		this.niveau = niveau;
	}

	@Override
	public String toString() {
		String sep = " - ";
		return new StringBuilder().append(Tools.formatPromotion(promotion)).append(sep).append(nom).append(sep)
				.append(niveau).toString();
	}

	public int getClasseId() {
		return classeId;
	}

	public void setClasseId(int classeId) {
		this.classeId = classeId;
	}

	public String getNom() {
		return nom;
	}

	public void setNom(String nom) throws LogicException {
		if (nom == null || nom.equals(""))
			throw new LogicException("nom vide");
		this.nom = nom;
	}

	public int getPromotion() {
		return promotion;
	}

	public void setPromotion(int promotion) throws LogicException {
		if (promotion < 1)
			throw new LogicException("promotion < 0");
		this.promotion = promotion;
	}

	public Niveau getNiveau() {
		return niveau;
	}

	public void setNiveau(Niveau niveau) throws LogicException {
		if (niveau == null)
			throw new LogicException("Niveau null");
		this.niveau = niveau;
	}

	public Set<Eleve> getEleves() {
		return eleves;
	}

	public void setEleves(Set<Eleve> eleves) {
		this.eleves = eleves;
	}

	public Map<Matiere, Enseignant> getEnseignantsResponsables() {
		return enseignantsResponsables;
	}

	public void setEnseignantsResponsables(
			Map<Matiere, Enseignant> enseignantsResponsables) {
		this.enseignantsResponsables = enseignantsResponsables;
	}

	public Set<Note> getNotes() {
		return notes;
	}

	public void setNotes(Set<Note> notes) {
		this.notes = notes;
	}

	public Set<Matiere> getMatieres() {
		return enseignantsResponsables.keySet();
	}
}
